$(function () {
    getUserInfo()
    $('#btnLogout').on('click', function () {
        layer.confirm('确定要退出吗？', { icon: 3, title: '提示' }, function (index) {
            localStorage.removeItem('token')
            location.href = '/login.html'
            layui.layer.close(index);
        });
    })
})

function getUserInfo() {
    axios({
        method: 'GET',
        url: '/my/userinfo',
    }).then(function (res) {

        renderName(res.data.data)
    }
    )
}

function renderName(userInfo) {
    var name = userInfo.nickname || userInfo.username
    var first = name[0].toUpperCase()
    $('.text-avatar').html(first)
}

function highlight(kw) {
    $('dd').removeClass('layui-this')
    $(`dd:contains(${kw})`).addClass('layui-this')
}